package old;

import java.io.IOException;


import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Transaction;


public class AjoutGroupeServlet extends HttpServlet {

	private static final long serialVersionUID = -2502133846514921463L;
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)	throws IOException {
		resp.setContentType("text/plain");
		String nomGroupe = req.getParameter("nomGroupe");
		System.out.println(nomGroupe);
		DatastoreService datastore= DatastoreServiceFactory.getDatastoreService();
		Transaction tx = datastore.beginTransaction();
		
		try {
			Entity groupe= new Entity("Groupes",nomGroupe);
			groupe.setProperty("nom", nomGroupe);
			datastore.put(groupe);
		    tx.commit();
		} finally {
		    if (tx.isActive()) {
		        tx.rollback();
		    }
		}
		resp.sendRedirect("/panneauAdministration/groupes.jsp");
	}
}
